<template>
  <j-upload v-model="fileList" :valueCopy="valueCopy" :returnUrl="false" :max='max' :fileType="fileType" :text="uploadText"></j-upload>
</template>

<script>
import JUpload from '@/components/jeecg/JUploadFZS'
import { getFileListByIds } from '@/api/api'
export default {
  components: { JUpload },
  data() {
    return {
      fileList: [],
      valueCopy: [],
    }
  },
  props: {
    ids: {
      type: String,
      default: '',
    },
    uploadText: {
      type: String,
      default: '上传文件',
    },
    fileType: {
      type: String,
      default: 'all',
    },
    max: {
      type: Number,
      required: false,
      default: 5
    },
  },
  watch: {
    fileList(newVal) {
      var fileIds = []
      var fileStr = ''
      newVal.forEach((item) => {
        fileIds.push(item.fileId)
      })
      fileStr = fileIds.join(',')
      this.$emit('getFileList', fileStr)
    },
    ids(newVal) {
      if (newVal) {
        getFileListByIds({ ids: newVal }).then((res) => {
          if (res.code == 200) {
            this.valueCopy = res.result
          }
        })
      }
    },
  },
  methods: {
    initFile(ids){
      getFileListByIds({ ids: ids }).then((res) => {
        if (res.code == 200) {
          this.valueCopy = res.result
        }
      })
    }
  },
}
</script>